<%@page import="org.omg.PortableServer.ID_ASSIGNMENT_POLICY_ID"%>
<%@page import="com.carple.dto.LoveBoard"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%!
String getTitleString(LoveBoard board){
	StringBuilder html = new StringBuilder(256);
	
	
	if (board.isDeleted()) {
		html.append("<span style='color:gray' ");
		html.append("onclick=\"alert('삭제된 글입니다.');\">");
		html.append(board.getTitle());
		html.append("&nbsp;(삭제된 글)");
		html.append("</span>");
	} else {
		html.append("<a href='javascript:viewboard(");
		html.append(board.getBoardNo());
		html.append(");'>");
		html.append(board.getTitle());
		html.append("</a>");
	}
	
	return html.toString();
}

%>
    
<!DOCTYPE html>

<html>
<head>
	<meta charset="utf-8" />
	<title>게시물 목록</title>	
	<link rel="Stylesheet" href="/carple/styles/main.css" />
 	<link rel="Stylesheet" href="/carple/styles/default.css" /> 
	<script type="text/javascript">
	function viewboard(boardno){
		<%
		//page넘버 설정
			String pageNo = request.getParameter("pageno");
			if(pageNo == null || pageNo.length() == 0){
				pageNo = "1";
			}
		%>
		<%if(session.getAttribute("loginuser")!=null){%>
			location.href = 'view.action?boardno=' + boardno+"&pageno=<%=pageNo%>";
		<%}else{%>
			location.href = '/carple/account/loginform.action?returnuri=/carple/loveboard/view.action?boardno='+boardno + "&pageno=<%=pageNo%>";
		<%}%>
	}
	</script>
	<script type="text/javascript">
	function lnavi(obj, type){
		if(type){
			obj.src = obj.src.replace('1.gif','2.gif');
			obj.onmouseout = function(){
				this.src = this.src.replace('2.gif','1.gif');
			}
		}
	}
	
	function headerSelector(header){
		location.href = "/carple/loveboard/list.action?owner="+header;
	}
</script>
</head>
<body>

	 <% pageContext.include("/WEB-INF/views/include/header.jsp"); %> 
	<br /><br /><br /><br /><br /><br /><br />
	<div id="pageContainer" >
		
		<div style="padding-top:25px;text-align:center;width:672px;margin:0 auto">
			<div style="align:right;text-align:right">
			<input id="male" type="button" value="남자" 
				style="width:100px;height:25px;"
				onclick="headerSelector('male')"
				/>
			<input id="female" type="button" value="여자" 
				style="width:100px;height:25px;"
				onclick="headerSelector('female')" 
				/>
			<input type="button" value="글쓰기" 
			style="width:300px;height:25px;"
			onclick="location.href='/carple/loveboard/writeform.action';" />
			</div>
			<% List<LoveBoard> boards = (List<LoveBoard>)request.getAttribute("boards"); %>
			<%if (boards != null && boards.size() > 0) { %>
			<br />
			<table border="1" style="align:right; margin:0 auto">
				<tr style="background-color:beige;height:25px">
					<th style="width:50px">번호</th>
					<th style="width:80px">머릿말</th>
					<th style="width:300px">제목</th>
					<th style="width:150px">작성자</th>
					<th style="width:120px">작성일</th>
					<th style="width:80px">조회수</th>
					
				</tr>
				<%for (LoveBoard board : boards){ %>
				<tr style="height:25px">
					<td style="text-align:center"><%=board.getBoardNo() %></td>
					<td style="text-align:center"><%=board.getHeader() %></td>
					<td style="text-align:left;padding:5px">
						<%= getTitleString(board) %>
					</td>
					<td style="text-align:center"><%=board.getEmailid() %></td>
					<td style="text-align:center"><%=board.getRegDate()%></td>
					<td style="text-align:center"><%=board.getReadCount() %></td>
				</tr>

				<%} %>
			</table>
			<%}else{ %>
				<div style='text-align:center' />등록된 게시물이 없습니다.</div>
			<%} %>
			<br /><br />
			
			<%= request.getAttribute("pager").toString() %>
	
		</div>
	</div>

</body>
</html>
